package com.bit.book.controller;

import com.bit.book.constant.Constants;
import com.bit.book.service.BookService;
import com.bit.book.service.UserService;
import jakarta.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;
    @RequestMapping("/login")
    public Boolean login(String name, String password, HttpSession session) {
        if(!StringUtils.hasLength(name) || !StringUtils.hasLength(password)) {
            return false;
        }
        //校验账号密码是否正确


        Boolean result = userService.checkPassword(name, password);
        if(result){
            session.setAttribute(Constants.SESSION_LOGIN_USER_NAME, name);
            return true;
        }
        return false;
    }
}
